#pragma once
#include "vec3.h"

namespace mray{

	struct BaseMaterial;
	struct Result;
	struct Ray;
	struct AABB;

	struct Collible{
		virtual bool Hit(Ray& ray, Result* pResult = nullptr)const = 0;
		virtual bool GetAABB(AABB& aabb)const = 0;
	};

	struct BaseObject : public Collible{
		BaseObject(BaseMaterial* pMtl, bool dSides){ m_pMtl = pMtl; m_dSides = dSides; }
		virtual ~BaseObject(){}

		virtual bool Hit(Ray& ray, Result* pResult = nullptr)const override{return false;}
		virtual bool GetAABB(AABB& aabb)const override{return false;}

		BaseMaterial* m_pMtl;
		bool m_dSides;
	};

	struct Sphere : public BaseObject{
		Sphere(const vec3& pos, float radius, BaseMaterial* pMtl, bool dSides);
		virtual ~Sphere(){}

		bool Hit(Ray& ray, Result* pResult = nullptr)const override;
		bool GetAABB(AABB& aabb)const override;

	private:
		vec3 m_pos;
		float m_radius;
		float m_invRadius;
	};

	//for area light
	struct Rectangle : public BaseObject{
		Rectangle(const vec3& pos, const vec3& look, const vec3& up, float halfw, float halfh, BaseMaterial* pMtl, bool dSides);
		virtual ~Rectangle(){}

		bool Hit(Ray& ray, Result* pResult = nullptr)const override;
		bool GetAABB(AABB& aabb)const override;

	protected:
		vec3 m_pos, m_look, m_up, m_right;
		float m_halfw, m_halfh;
	};

}













